<?php

class Qtadmin_IndexController extends Zend_Controller_Action
{

    public function init()
    {
       $this->view->mod = $this->_request->getModuleName();
    $this->view->cot = $this->_request->getParam('controller');//lay duoc ten controller hien hanh
    }

     public function indexAction()
    {
        if($this->_request->getPost())
        {
           $au = new Zend_Auth_Adapter_DbTable();
       //Khai bao ten table va 2 colum chua du lieu can kiem tra
        $au->setTableName('tbl_user')
        	->setIdentityColumn('user')
        	->setCredentialColumn('password');
        	
       //tao 2 bien lay du lieu dau vao
       $u = $this->_request->getParam('user');
       $p = md5($this->_request->getParam('pass'));
       
       //cho du lieu dau vao doi tuong $au
       $au->setIdentity($u)
       		->setCredential($p);
       		
       	//lay du lieu ra
       	$au->getDbSelect();
       	
       	//lay ket qua truy van so sanh du lieu
       	$auth = Zend_Auth::getInstance();
       	$result = $auth->authenticate($au);
       	
       	//if
       	$kq = $result->isValid();
       	if($kq)
       	{
       		//bo field khong can lay du lieu
       		$info = $au->getResultRowObject(null,array('password'));
       		
       		//ghi du lieu vao session
       		$auth->getStorage()->write($info);
       	
       		//thuc hien ca len khi dang nhap khong thah cong
       		echo 'dang nhap thanh cong';
       		$this->_redirect('qtadmin/menu');
            
        }
        else
        {
            echo 'dang nhap that baij';
        }
    }
   } 
   
   public function logoutAction()
   {
    Zend_Session::destroy(true);
    $this->_redirect('qtadmin/menu');
   }


}



